<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>中南财经政法大学就业管理系统</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Segoe UI', 'Microsoft YaHei', sans-serif;
        }

        body {
            background: linear-gradient(135deg, #1a2a6c, #b21f1f, #1a2a6c);
            background-size: 400% 400%;
            animation: gradientBG 15s ease infinite;
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 100vh;
            color: #333;
            padding: 20px;
        }

        @keyframes gradientBG {
            0% { background-position: 0% 50%; }
            50% { background-position: 100% 50%; }
            100% { background-position: 0% 50%; }
        }

        .login-container {
            width: 100%;
            max-width: 420px;
            background: rgba(255, 255, 255, 0.95);
            border-radius: 15px;
            overflow: hidden;
            box-shadow: 0 15px 35px rgba(0, 0, 0, 0.25);
            padding: 30px;
        }

        .university-header {
            text-align: center;
            margin-bottom: 25px;
        }

        .university-logo {
            width: 80px;
            height: 80px;
            margin: 0 auto 15px;
            background: linear-gradient(to bottom right, #1a2a6c, #4a7bd5);
            border-radius: 50%;
            display: flex;
            justify-content: center;
            align-items: center;
        }

        .university-logo i {
            font-size: 40px;
            color: white;
        }

        .university-header h1 {
            font-size: 24px;
            color: #1a2a6c;
            margin-bottom: 5px;
            font-weight: 600;
        }

        .university-header p {
            color: #666;
            font-size: 14px;
        }

        .form-tabs {
            display: flex;
            margin-bottom: 25px;
            background: #f0f4f8;
            border-radius: 50px;
            padding: 5px;
        }

        .form-tab {
            flex: 1;
            padding: 12px 15px;
            border: none;
            background: transparent;
            font-size: 15px;
            font-weight: 600;
            cursor: pointer;
            border-radius: 50px;
            transition: all 0.3s ease;
            color: #555;
        }

        .form-tab.active {
            background: #1a2a6c;
            color: white;
            box-shadow: 0 4px 8px rgba(26, 42, 108, 0.2);
        }

        .form-panel {
            display: none;
        }

        .form-panel.active {
            display: block;
            animation: fadeIn 0.5s ease;
        }

        @keyframes fadeIn {
            from { opacity: 0; transform: translateY(10px); }
            to { opacity: 1; transform: translateY(0); }
        }

        .form-group {
            margin-bottom: 20px;
        }

        .form-group label {
            display: block;
            margin-bottom: 8px;
            font-weight: 500;
            color: #444;
            font-size: 14px;
        }

        .input-with-icon {
            position: relative;
        }

        .input-with-icon i {
            position: absolute;
            left: 15px;
            top: 50%;
            transform: translateY(-50%);
            color: #777;
        }

        .form-control {
            width: 100%;
            padding: 14px 14px 14px 45px;
            border: 2px solid #e1e5eb;
            border-radius: 8px;
            font-size: 15px;
            transition: all 0.3s;
        }

        .form-control:focus {
            border-color: #4a7bd5;
            box-shadow: 0 0 0 3px rgba(74, 123, 213, 0.2);
            outline: none;
        }

        .btn {
            display: block;
            width: 100%;
            padding: 14px;
            border: none;
            border-radius: 8px;
            font-size: 16px;
            font-weight: 600;
            cursor: pointer;
            transition: all 0.3s ease;
            text-align: center;
        }

        .btn-primary {
            background: linear-gradient(to right, #1a2a6c, #4a7bd5);
            color: white;
            margin-top: 10px;
            box-shadow: 0 4px 12px rgba(26, 42, 108, 0.25);
        }

        .btn-primary:hover {
            background: linear-gradient(to right, #15205a, #3a6bc9);
            box-shadow: 0 6px 15px rgba(26, 42, 108, 0.35);
            transform: translateY(-2px);
        }

        .btn-success {
            background: linear-gradient(to right, #2b8c3e, #4caf50);
            color: white;
            margin-top: 15px;
            box-shadow: 0 4px 12px rgba(43, 140, 62, 0.25);
        }

        .btn-success:hover {
            background: linear-gradient(to right, #247a35, #3d8b40);
            box-shadow: 0 6px 15px rgba(43, 140, 62, 0.35);
            transform: translateY(-2px);
        }

        .form-footer {
            text-align: center;
            margin-top: 20px;
            font-size: 14px;
            color: #666;
            padding-top: 15px;
            border-top: 1px solid #eee;
        }

        .form-footer a {
            color: #1a2a6c;
            text-decoration: none;
            font-weight: 500;
        }

        .form-footer a:hover {
            text-decoration: underline;
        }

        .notification {
            padding: 12px;
            border-radius: 8px;
            margin-bottom: 20px;
            text-align: center;
            font-size: 14px;
            display: none;
        }

        .notification.info {
            background: #e3f2fd;
            color: #1a2a6c;
            border-left: 4px solid #1a2a6c;
        }

        .notification.success {
            background: #e8f5e9;
            color: #2b8c3e;
            border-left: 4px solid #2b8c3e;
        }

        .notification.error {
            background: #ffebee;
            color: #c62828;
            border-left: 4px solid #c62828;
        }

        .copyright {
            text-align: center;
            margin-top: 25px;
            color: rgba(255, 255, 255, 0.7);
            font-size: 13px;
        }
    </style>
</head>
<body>
<div class="login-container">
    <div class="university-header">
        <div class="university-logo">
            <i class="fas fa-graduation-cap"></i>
        </div>
        <h1>中南财经政法大学</h1>
        <p>就业管理与服务平台</p>
    </div>

    <div class="form-tabs">
        <button class="form-tab active" data-tab="registered">已注册用户</button>
        <button class="form-tab" data-tab="unregistered">新用户注册</button>
    </div>

    <div id="notification" class="notification"></div>

    <!-- 已注册用户的登录表单 -->
    <div id="registered-form" class="form-panel active">
        <form>
            <div class="form-group">
                <label for="username">用户ID</label>
                <div class="input-with-icon">
                    <i class="fas fa-user"></i>
                    <input type="text" id="username" class="form-control" placeholder="请输入您的用户ID" required>
                </div>
            </div>

            <div class="form-group">
                <label for="password">密码</label>
                <div class="input-with-icon">
                    <i class="fas fa-lock"></i>
                    <input type="password" id="password" class="form-control" placeholder="请输入您的密码" required>
                </div>
            </div>

            <button type="button" class="btn btn-primary" onclick="submitLogin()">
                <i class="fas fa-sign-in-alt"></i> 登录系统
            </button>
        </form>
    </div>

    <!-- 未注册用户的表单 -->
    <div id="unregistered-form" class="form-panel">
        <form>
            <div class="form-group">
                <p style="text-align: center; margin: 20px 0; line-height: 1.6; color: #555;">
                    欢迎使用中南财经政法大学就业管理系统<br>
                    点击下方按钮获取新用户ID
                </p>
            </div>

            <button type="button" class="btn btn-success" id="getNewIdBtn">
                <i class="fas fa-user-plus"></i> 获取新用户ID
            </button>

            <div class="form-footer">
                获取ID后初始密码为 <strong>123456</strong><br>请尽快登录并修改密码
            </div>
        </form>
    </div>

    <div class="copyright">
        © 2023 中南财经政法大学就业指导中心
    </div>
</div>

<script>
    //标签切换
    document.addEventListener('DOMContentLoaded', function() {
        // 标签切换功能
        const tabs = document.querySelectorAll('.form-tab');
        const panels = document.querySelectorAll('.form-panel');

        tabs.forEach(tab => {
            tab.addEventListener('click', function() {
                const targetTab = this.getAttribute('data-tab');

                // 更新标签状态
                tabs.forEach(t => t.classList.remove('active'));
                this.classList.add('active');

                // 更新面板状态
                panels.forEach(panel => {
                    panel.classList.remove('active');
                    if (panel.id === `${targetTab}-form`) {
                        panel.classList.add('active');
                    }
                });

                // 清空通知
                document.getElementById('notification').style.display = 'none';
            });
        });

        // 获取新ID按钮功能
        const getNewIdBtn = document.getElementById('getNewIdBtn');
        getNewIdBtn.addEventListener('click', function() {
            const notification = document.getElementById('notification');
            notification.className = 'notification info';
            notification.innerHTML = '<i class="fas fa-spinner fa-spin"></i> 正在生成新用户ID，请稍候...';
            notification.style.display = 'block';

            // 原始功能 - 获取新用户ID
            fetch('/zuel/register')
                .then(response => {
                    if (!response.ok) {
                        throw new Error('网络响应异常');
                    }
                    return response.json();
                })
                .then(data => {
                    notification.className = 'notification success';
                    notification.innerHTML = `新用户ID已生成: <strong>${data.id}</strong><br>初始密码: <strong>123456</strong><br>请尽快登录并修改密码`;

                    // 切换到登录表单并填充用户名
                    setTimeout(() => {
                        tabs[0].click();
                        document.getElementById('username').value = data.id;
                        document.getElementById('password').value = '123456';
                    }, 3000);
                })
                .catch(error => {
                    console.error('获取新用户ID失败:', error);
                    notification.className = 'notification error';
                    notification.innerHTML = `请求失败: ${error.message}`;
                });
        });
    });
    //提交登录
    function submitLogin() {
        const username = document.getElementById('username').value;
        const password = document.getElementById('password').value;
        const notification = document.getElementById('notification');

        if (!username || !password) {
            notification.className = 'notification error';
            notification.innerHTML = '请输入用户名和密码';
            notification.style.display = 'block';
            return;
        }

        // 显示登录中状态
        const loginBtn = document.querySelector('.btn-primary');
        const originalText = loginBtn.innerHTML;
        loginBtn.innerHTML = '<i class="fas fa-spinner fa-spin"></i> 登录中...';
        loginBtn.disabled = true;

        notification.className = 'notification info';
        notification.innerHTML = '<i class="fas fa-spinner fa-spin"></i> 正在验证您的登录信息...';
        notification.style.display = 'block';

        // 原始登录功能
        fetch('/zuel/login', {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json'
            },
            body: JSON.stringify({
                username: username,
                password: password
            })
        })
            .then(response => response.json())
            .then(data => {
                if (data.data === '1') {
                    notification.className = 'notification success';
                    notification.innerHTML = '登录成功！正在跳转到用户主页...';
                    setTimeout(() => {
                        window.location.href = 'UserHome.html';
                    }, 1500);
                } else if (data.data === '3') {
                    notification.className = 'notification success';
                    notification.innerHTML = '登录成功！正在跳转到企业主页...';
                    setTimeout(() => {
                        window.location.href = 'CompanyHome.html';
                    }, 1500);
                } else {
                    notification.className = 'notification error';
                    notification.innerHTML = '登录失败，用户名或密码错误';
                    loginBtn.innerHTML = originalText;
                    loginBtn.disabled = false;
                }
            })
            .catch(error => {
                console.error('登录失败:', error);
                notification.className = 'notification error';
                notification.innerHTML = `登录失败: ${error.message}`;
                loginBtn.innerHTML = originalText;
                loginBtn.disabled = false;
            });
    }
</script>
</body>
</html>